/* Copyright(C): Leaf Johnson 2009,2010

    This file is part of leaf-lib.

    leaf-lib is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    leaf-lib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with leaf-lib.  If not, see <http://www.gnu.org/licenses/>.


 * 
 * 
 */


#ifndef SYSMSGHANDLER_H_INCLUDED
#define SYSMSGHANDLER_H_INCLUDED

static inline void handle_sys_msg( pSysMsg msg )
{
	SysMsgHandler hand = handlers[ msg->id ];
	if( hand != NULL )
	{
		hand( msg );
	}
}

static inline void handle_sys_msg_ack( pSysMsg msg )
{
	handle_sys_msg( msg );
	ack_msg( &( msg->mcb ) );
}

static inline void set_handler( uint8_t mid, SysMsgHandler hand )
{
	handlers[ mid ] = hand;
}
static inline void reset_handler( uint8_t mid )
{
	handlers[ mid ] = NULL;
}

static inline void clr_handler( uint8_t mid )
{
	set_handler( mid, NULL );
}

#define handleSysMsg(m) handle_sys_msg(m)

#endif /* SYSMSGHANDLER_H_INCLUDED */
